<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>系统日志</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        //----------------------------------------------------------------------
        Ext.define('SysLog', {
          extend : 'Ext.data.Model',
          fields : [{name: 'id'},
            {
              name: 'company_name',
              mapping:'company',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'department_name',
              mapping:'department',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name: 'employee_name',
              mapping:'employee',
              convert:function(value,record){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },
            {name: 'c_name'},
            {name: 'a_name'},
            {name: 'description'},
            {name: 'created_at'}
          ]
        });

        var sysLogDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'SysLog',
          proxy : {
            type : 'ajax',
            url : '/admin/getAllSysLog',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },
          pageSize:pageSize,
          autoLoad:true
        });

        //生成要订单的产品的Grid
        var sysLogGrid = Ext.create('Ext.grid.Panel', {
          title:'系统日志列表',
          store: sysLogDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '公司',
              dataIndex: 'company_name',
              width: 60
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '操作员',
              dataIndex: 'employee_name',
              width: 60
            },{
              header: '控制器',
              dataIndex: 'c_name',
              width: 100
            },{
              header: '方法',
              dataIndex: 'a_name',
              width: 210
            },{
              header: '信息',
              dataIndex: 'description',
              width: 750
            },{
              header: '日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          selModel :Ext.create('Ext.selection.CheckboxModel'),
          width: screenWidth-185,
          height: 375,
          frame: true,
          tbar: [{
              text: '删除',
              iconCls: 'remove',
              handler : function(){
                var record = sysLogSM.getSelected;
                if (!record) {
                  return false;
                }
                sysLogDS.remove(record);
              }
            }],
          bbar: Ext.create('Ext.toolbar.Paging', {
            pageSize: 20,
            store: sysLogDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });

        sysLogGrid.on('itemdblclick', function(gridPanel, record,item,index,e,options){
          description.setValue(sysLogDS.getAt(index).get('description'));
        });
        
        var description = Ext.create('Ext.form.TextArea', {
          fieldLabel: '错误详细内容',
          name: 'description',
          allowBlank: false,
          height: 160,
          width: screenWidth-255
        });

        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-155,
          height: totalHeight,autoScroll:true,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[sysLogGrid,description]
        });
        workbenchPanel.render("sys_log_list");
      })
    </script>
  </head>
  <body>
    <div id="sys_log_list"></div>
  </body>
</html>
